package com.common.ui;


import android.text.TextUtils;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.common.R;
import com.common.entity.NoteBean;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class NoteAdapter extends BaseQuickAdapter<NoteBean, BaseViewHolder> {

    private TextView tvNoteTitle;
    private TextView tvNoteLastTime;
    private TextView tvNoteContent;
    private TextView tvDelete;

    public NoteAdapter(@Nullable List<NoteBean> data) {
        super(R.layout.item_note, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, NoteBean item) {

        tvNoteTitle = (TextView) helper.getView(R.id.tv_note_title);
        tvNoteLastTime = (TextView) helper.getView(R.id.tv_note_last_time);
        tvNoteContent = (TextView) helper.getView(R.id.tv_note_content);
        tvNoteTitle.setText(item.getTitle());
        tvNoteContent.setText(item.getContent());
        tvDelete = helper.getView(R.id.tv_delete);
        if (!TextUtils.isEmpty(item.getUpdate_time())) {
            String[] times = item.getUpdate_time().split(" ");
            Date date = new Date();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            if (simpleDateFormat.format(date).equals(times[0])) {
                tvNoteLastTime.setText(times[1]);
            } else {
                tvNoteLastTime.setText(item.getUpdate_time());
            }
        }
    }
}
